/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SnpDbHandling;

import SnpDbEntities.Category;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Łukasz 'byku' Guzik
 */
public class CategoryRecord
{
    private final Category category;

    public CategoryRecord(Category category)
    {
	this.category = category;
    }

    public final Category getCategory()
    {
	return category;
    }

    public static CategoryRecord getFromResultSet(ResultSet rs) throws
	    SQLException
    {
	Category category = new Category();

	category.setId(rs.getInt("ID"));
	category.setName(rs.getNString("Name"));
	category.setParentId(rs.getInt("ParentID"));

	return new CategoryRecord(category);
    }

    public void insertIntoResultSet(ResultSet rs) throws SQLException
    {
	rs.updateNString("Name", category.getName());
	if(category.getParentId() == 0)
	{
	    rs.updateNull("ParentID");
	} else
	{
	    rs.updateInt("ParentID", category.getParentId());
	}
    }
}
